﻿@using A2.ERP.Models
@{
    List<t_log> logs = ViewBag.logs;
    int currentIndex = ViewBag.currentIndex;
    int totalCount = ViewBag.totalCount;
    int pageSize = 10;
    int totalPage = totalCount / pageSize;
}

<section id="systemLog">
    <table class="table">
        <tbody>
            @foreach (var log in logs)
            {
                <tr>
                    <td>@log.LogID</td>
                    <td>@log.LogTime</td>
                    <td>@log.Description</td>
                </tr>
            }
        </tbody>
    </table>
    <nav aria-label="Page navigation log">
        <ul class="pagination">
            <li class="page-item">
                <a class="page-link" href="#" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                    <span class="sr-only">Previous</span>
                </a>
            </li>
            @for (int provIndex = currentIndex - 6 <= 0 ? 1 : currentIndex - 6; provIndex < currentIndex; provIndex++)
            {
                <li class="page-item"><a class="page-link" href="#">@provIndex</a></li>
            }
            <li class="page-item active"><a class="page-link" href="#">@currentIndex</a></li>
            @for (int nextIndex = currentIndex + 1; nextIndex < currentIndex + 5 && nextIndex < totalPage; nextIndex++)
            {
                <li class="page-item"><a class="page-link" href="#">@nextIndex</a></li>
            }
            <li class="page-item">
                <a class="page-link" href="#" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                    <span class="sr-only">Next</span>
                </a>
            </li>
        </ul>
    </nav>
</section>

<script>
    ;
    !function () {
        var $pageLink = $('#systemLog .page-link');

        // methods
        var loadNewPage = function (pageIndex, pageSize) {
            $tab.reloadTab('#systemLog', [{
                pageIndex: pageIndex
            }, {
                pageSize: pageSize
            }]);
        };

        // bind

        $pageLink.on('click', function () {
            loadNewPage($(this).html(), 10);
        });
    }();
</script>